#ifndef WEBUI_QUERY_H_INCLUDED_
#define WEBUI_QUERY_H_INCLUDED_

#include <string>
#include <boost/lexical_cast.hpp>

namespace webui {

class Query
{
public:
	struct RVar
	{
		template<typename T>
		operator T () const;

		RVar(const std::string& val_) : val(val_) {}

		const std::string& val;
	};

	RVar operator[] (const std::string& key) const;

	template<typename T>
	T cast(const std::string& key) const;

	Query(const std::string& rhs);

private:
	const std::string& query_;
	mutable std::string value_;
};

template<typename T>
Query::RVar::operator T () const
{
	return boost::lexical_cast<T>(val);
}

template<typename T>
T Query::cast(const std::string& key) const
{
	this->operator[](key);
	return boost::lexical_cast<T>(value_);
}

} // namespace webui

#endif // WEBUI_QUERY_H_INCLUDED_